import request from '@/utils/request'

export interface LoginData {
  email: string
  password: string
}

export interface LoginRes {
  token: string
}

export interface UserState {
  id?: number
  name?: string
  avatar?: string
  createdAt?: string
  loginName?: string
  phone?: string
  totalIncome?: number
  totalSpent?: number
  userState?: number
}

export function login(data: LoginData): Promise<any> {
  return request.post<LoginRes>('/login', data)
}

export function logout() {
  return request.post('/user/logout')
}

export function getUserInfo(id) {
  return request<UserState>('/user/getUserInfo', { params: { id } })
}

export function getEmailCode(): Promise<any> {
  return request.get('/user/email-code')
}

export function resetPassword(): Promise<any> {
  return request.post('/user/reset-password')
}

export function register(): Promise<any> {
  return request.post('/user/register')
}
